﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace ModeloGaleriaNET
{
    public class ServerConnData
    {
        private readonly uint DEFAULT_TIMEOUT = 20;
        private readonly int DEFAULT_SEGURIDAD = 0;
        /// <summary>
        /// URL de jUDDI (no se puede tocar)
        /// </summary>
        private String juddi;
        /// <summary>
        /// URL del servidor de la aplicación
        /// </summary>
        private String servidorArte;
        /// <summary>
        /// Contraseña
        /// </summary>
        private String password;
        /// <summary>
        /// Usuario
        /// </summary>
        private String user;
        /// <summary>
        /// TimeOut
        /// </summary>
        private uint timeOut;
        /// <summary>
        /// Habilitar comunicación segura
        /// </summary>
        private int seguridad;

        private ServerConnData()
        {
            this.juddi = Properties.Settings.Default.jUDDIURL;
            this.servidorArte = Properties.Settings.Default.gestorURL;
            this.password = Utilities.DesencriptarRSA(Properties.Settings.Default.PassGestor);
            this.user = Properties.Settings.Default.UserGestor;
            this.timeOut = Properties.Settings.Default.TimeOut;
            this.seguridad = Properties.Settings.Default.Seguridad;
        }

        public static readonly ServerConnData Instance = new ServerConnData();

        public String jUDDI
        {
            get { return juddi; }
            set { juddi = value; }
        }

        public String User
        {
            get { return user; }
            set { user = value; }
        }

        public String Password
        {
            get { return password; }
            set { password = value; }
        }

        public String URLGestor
        {
            get { return servidorArte; }
            set { servidorArte = value; }
        }

        public int Seguridad
        {
            get { return seguridad; }
            set { seguridad = value; }
        }

        public uint TimeOut
        {
            get { return timeOut; }
            set { timeOut = value; }
        }

        public void Save()
        {
            Properties.Settings.Default.UserGestor = user;
            Properties.Settings.Default.jUDDIURL = juddi;
            Properties.Settings.Default.PassGestor = Utilities.EncriptarRSA(password);
            Properties.Settings.Default.gestorURL = servidorArte;
            Properties.Settings.Default.Seguridad = seguridad;
            Properties.Settings.Default.ModeloGaleriaNET_jUDDIInquiry_UDDI_Inquiry_Port = "http://" + juddi + ":8080/juddiv3/services/inquiry";
            Properties.Settings.Default.ModeloGaleriaNET_jUDDISecurity_UDDI_Security_Port = "http://" + juddi + ":8080/juddiv3/services/security";
            Properties.Settings.Default.ModeloGaleriaNET_jUDDIInquiry_UDDI_Inquiry_Port_SSL = "https://" + juddi + ":8443/juddiv3/services/inquiry";
            Properties.Settings.Default.ModeloGaleriaNET_jUDDISecurity_UDDI_Security_Port_SSL = "https://" + juddi + ":8443/juddiv3/services/security";
            Properties.Settings.Default.ModeloGaleriaNET_jUDDIPublish_UDDI_Publish_Port = "http://" + juddi + ":8080/juddiv3/services/publish";
            Properties.Settings.Default.ModeloGaleriaNET_jUDDIPublish_UDDI_Publish_Port_SSL = "https://" + juddi + ":8443/juddiv3/services/publish";


            Properties.Settings.Default.ModeloGaleriaNET_GaleriasCommands_GaleriasCommands = "http://" + servidorArte + ":8080/NucleoSOR/services/GaleriasCommands.GaleriasCommandsHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_SubastasQueries_SubastasQueries = "http://" + servidorArte + ":8080/NucleoSOR/services/SubastasQueries.SubastasQueriesHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_GaleriasCommands_GaleriasCommands_SSL = "https://" + servidorArte + ":8443/NucleoSOR/services/GaleriasCommands.GaleriasCommandsHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_SubastasQueries_SubastasQueries_SSL = "https://" + servidorArte + ":8443/NucleoSOR/services/SubastasQueries.SubastasQueriesHttpSoap11Endpoint/";
            
            
            
            Properties.Settings.Default.ModeloGaleriaNET_VendedorArteCommands_VendedorArteCommands = "http://" + servidorArte + ":8080/NucleoSOR/services/VendedorArteCommands.VendedorArteCommandsHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_VendedorArteCommands_VendedorArteCommands_SSL = "https://" + servidorArte + ":8443/NucleoSOR/services/VendedorArteCommands.VendedorArteCommandsHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_WebReference_GaleriasQueries = "http://" + servidorArte + ":8080/NucleoSOR/services/GaleriasQueries.GaleriasQueriesHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_WebReference_GaleriasQueries_SSL = "https://" + servidorArte + ":8443/NucleoSOR/services/GaleriasQueries.GaleriasQueriesHttpSoap11Endpoint/";
            
            Properties.Settings.Default.ModeloGaleriaNET_PujasQueries_PujasQueries = "http://" + servidorArte + ":8080/NucleoSOR/services/PujasQueries.PujasQueriesHttpSoap11Endpoint/";
            Properties.Settings.Default.ModeloGaleriaNET_PujasQueries_PujasQueries = "https://" + servidorArte + ":8443/NucleoSOR/services/PujasQueries.PujasQueriesHttpSoap11Endpoint/";

            Properties.Settings.Default.ModeloGaleriaNET_Police_GandalfService = "http://" + servidorArte + ":8080/gandalf/GandalfService/";
            Properties.Settings.Default.ModeloGaleriaNET_Police_GandalfService_SSL = "https://" + servidorArte + ":8443/gandalf/GandalfService/";

            Properties.Settings.Default.ModeloGaleriaNET_SubastasQueries_Safe_SubastasQueriesService = "http://" + servidorArte + ":8080/gestor-webservices/";
            Properties.Settings.Default.ModeloGaleriaNET_SubastasQueries_Safe_SubastasQueriesService_SSL = "http://" + servidorArte + ":8080/gestor-webservices/";

            Properties.Settings.Default.ModeloGaleriaNET_VendedorArteCommands_Safe_VendedorArteCommandsService = "http://" + servidorArte + ":8080/gestor-webservices/";
            Properties.Settings.Default.ModeloGaleriaNET_VendedorArteCommands_Safe_VendedorArteCommandsService = "https://" + servidorArte + ":8443/gestor-webservices/";

            Properties.Settings.Default.ModeloGaleriaNET_GaleriasCommands_Safe_UsuariosCommandsService = "http://" + servidorArte + ":8080/gestor-webservices/";
            Properties.Settings.Default.ModeloGaleriaNET_GaleriasCommands_Safe_UsuariosCommandsService_SSL = "https://" + servidorArte + ":8443/gestor-webservices/";

            Properties.Settings.Default.ModeloGaleriaNET_GaleriasQueries_Safe_UsuariosQueriesService = "http://" + servidorArte + ":8080/gestor-webservices/";
            Properties.Settings.Default.ModeloGaleriaNET_GaleriasQueries_Safe_UsuariosQueriesService_SSL = "https://" + servidorArte + ":8443/gestor-webservices/";
            
            Properties.Settings.Default.TimeOut = timeOut;
            Properties.Settings.Default.Save();
        }

        public void Clear()
        {
            juddi = string.Empty;
            user = string.Empty;
            password = string.Empty;
            servidorArte = string.Empty;
            timeOut = DEFAULT_TIMEOUT;
            seguridad = DEFAULT_SEGURIDAD;
            Save();
        }

        public bool IsEmpty()
        {
            return string.IsNullOrWhiteSpace(user) ||
                   string.IsNullOrWhiteSpace(juddi) ||
                   string.IsNullOrWhiteSpace(password) ||
                   string.IsNullOrWhiteSpace(servidorArte);
        }

        public string ActiveMQURL
        {
            get { return "tcp://192.168.1.55:61616"; }
        }
    }
}
